package com.gis507.test.AISTest4;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * 1、实现Writable接口
 * 2、属性有：speed，unixTime，lon_d，lat_d，(String)draught(类型),Length,Width,CallSign,Heading,Course,Rot
 */
public class AISDataBean implements Writable {

    private double speed;
    private long unixTime;
    private double lon_d;
    private double lat_d;
    private String draught;
    private String length;
    private String width;
    private String callsign;
//    private double heading;
    private double course;
    private double rot;

    public AISDataBean(double speed, long unixTime, double lon_d, double lat_d, String draught, String length, String width, String callsign, double course, double rot) {
        this.speed = speed;
        this.unixTime = unixTime;
        this.lon_d = lon_d;
        this.lat_d = lat_d;
        this.draught = draught;
        this.length = length;
        this.width = width;
        this.callsign = callsign;
//        this.heading = heading;
        this.course = course;
        this.rot = rot;
    }

    public AISDataBean() {
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public long getUnixTime() {
        return unixTime;
    }

    public void setUnixTime(long unixTime) {
        this.unixTime = unixTime;
    }

    public double getLon_d() {
        return lon_d;
    }

    public void setLon_d(double lon_d) {
        this.lon_d = lon_d;
    }

    public double getLat_d() {
        return lat_d;
    }

    public void setLat_d(double lat_d) {
        this.lat_d = lat_d;
    }

    public String getDraught() {
        return draught;
    }

    public void setDraught(String draught) {
        this.draught = draught;
    }

    public String getLength() {
        return length;
    }

    public void setLength(String length) {
        this.length = length;
    }

    public String getWidth() {
        return width;
    }

    public void setWidth(String width) {
        this.width = width;
    }

    public String getCallsign() {
        return callsign;
    }

    public void setCallsign(String callsign) {
        this.callsign = callsign;
    }

//    public double getHeading() {
//        return heading;
//    }
//
//    public void setHeading(double heading) {
//        this.heading = heading;
//    }

    public double getCourse() {
        return course;
    }

    public void setCourse(double course) {
        this.course = course;
    }

    public double getRot() {
        return rot;
    }

    public void setRot(double rot) {
        this.rot = rot;
    }

    @Override
    public String toString() {
        return speed + "," + unixTime + "," + lon_d + "," + lat_d + "," + draught + ","
                + length + "," + width + "," + callsign + "," + course + "," + rot ;
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {

        //speed，unixTime，lon_d，lat_d，(String)draught(类型),Length,Width,CallSign,Heading,Course,Rot
        dataOutput.writeDouble(speed);
        dataOutput.writeLong(unixTime);
        dataOutput.writeDouble(lon_d);
        dataOutput.writeDouble(lat_d);
        dataOutput.writeUTF(draught);
        dataOutput.writeUTF(length);
        dataOutput.writeUTF(width);
        dataOutput.writeUTF(callsign);
//        dataOutput.writeDouble(heading);
        dataOutput.writeDouble(course);
        dataOutput.writeDouble(rot);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {

        this.speed = dataInput.readDouble();
        this.unixTime = dataInput.readLong();
        this.lon_d = dataInput.readDouble();
        this.lat_d = dataInput.readDouble();
        this.draught = dataInput.readUTF();
        this.length = dataInput.readUTF();
        this.width = dataInput.readUTF();
        this.callsign = dataInput.readUTF();
//        this.heading = dataInput.readDouble();
        this.course = dataInput.readDouble();
        this.rot = dataInput.readDouble();

    }
}
